﻿using System;
using System.IO;
using Mono.Cecil;
using Mono.Cecil.Pdb;

namespace CSLuaTest
{
	// Token: 0x02000003 RID: 3
	public static class CSBuilder
	{
		// Token: 0x06000004 RID: 4 RVA: 0x00002168 File Offset: 0x00000368
		public static void build(string fileName, string outFolder)
		{
			AssemblyDefinition assembly = AssemblyDefinition.ReadAssembly(fileName);
			new DirectoryInfo(outFolder).Create();
			AstBuilder astBuilder = new AstBuilder(new DecompilerContext(assembly.MainModule));
			astBuilder.AddAssembly(assembly, false);
			StringWriter output = new StringWriter();
			astBuilder.GenerateCode(new PlainTextOutput(output));
			File.WriteAllText(string.Concat(new object[]
			{
				outFolder,
				"/",
				assembly.MainModule,
				".cs"
			}), output.ToString());
		}

		// Token: 0x06000005 RID: 5 RVA: 0x000021E8 File Offset: 0x000003E8
		private static void LoadSymbols(string fileName, ModuleDefinition module)
		{
			string pdbName = Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName) + ".pdb");
			if (File.Exists(pdbName))
			{
				using (Stream s = File.OpenRead(pdbName))
				{
					module.ReadSymbols(new PdbReaderProvider().GetSymbolReader(module, s));
				}
				return;
			}
		}
	}
}
